
# 浅拷贝和深拷贝

# 两个变量共同绑定用一个对象
# L1 = [1, 2, [3.0, 0.14], 4]
# L2 = L1
# L2[3] = 4.5
# L2[2][1] = 0.1415
# print(L1)  # [1, 2, [3.0, 0.1415], 4.5]
# print(L2)  # [1, 2, [3.0, 0.1415], 4.5]

# 浅拷贝
# L1 = [1, 2, [3.0, 0.14], 4]
# L2 = L1.copy()
# L2[3] = 4.5
# L2[2][1] = 0.1415
# print(L1)  # [1, 2, [3.0, 0.1415], 4]
# print(L2)  # [1, 2, [3.0, 0.1415], 4.5]

# 深拷贝
import copy  # 导入拷贝copy模块
L1 = [1, 2, [3.0, 0.14], 4]
L2 = copy.deepcopy(L1)  # 深拷贝
L2[3] = 4.5
L2[2][1] = 0.1415
print(L1)  # [1, 2, [3.0, 0.14], 4]
print(L2)  # [1, 2, [3.0, 0.1415], 4.5]
